package cn.xuexiyuan.springdatamongodemo.common;

import cn.xuexiyuan.springdatamongodemo.common.constant.Result;
import lombok.Data;

/**
 * @Description: 响应消息实体
 * @Author 左龙龙
 * @Date 20-1-14
 * @Version 1.0
 **/
@Data
public class Response<T>{
    private int code;
    private T data;
    private String msg;

    private Response(int code, T data, String msg){
        this.code =code;
        this.data = data;
        this.msg = msg;
    }

    public static <T> Response<T> buildSuccess(T data, String msg) {
        return new Response<T>(Result.SUCCESS, data, msg);
    }

    public static <T> Response<T> buildSuccess(T data) {
        return buildSuccess(data, null);
    }

    public static Response buildFail(int code, String msg) {
        return new Response(code, null, msg);
    }

    public static <T> Response<T> buildFail(String msg) {
        return buildFail(Result.FAIL, msg);
    }

}
